<template>
  <d2-container class="tasklist">
    <template slot="header">任务列表</template>
    <el-row :gutter="22">
      <el-col :span="3">
        <el-input size="small" v-model="baby" placeholder="请输入宝贝id"></el-input>
      </el-col>
      <el-col :span="3">
        <el-input size="small" v-model="order_id" placeholder="请输入订单id"></el-input>
      </el-col>
      <el-col :span="3">
        <el-input size="small" v-model="user_name" placeholder="请输入用户名"></el-input>
      </el-col>
      <el-col :span="3">
        <el-input size="small" v-model="shop_name" placeholder="请输入商户名(店铺)"></el-input>
      </el-col>
      <el-col :span="6">
        <el-date-picker
          style="width:100%;"
          size="small"
          v-model="timeval"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
          format="yyyy 年 MM 月 dd 日"
          value-format="yyyy-MM-dd HH:mm:ss">
        </el-date-picker>
      </el-col>
      <el-col :span="2">
        <el-button size="mini" type="primary" @click="onSearch">查询</el-button>
      </el-col>
    </el-row>
    <el-table :data="tableData" border style="width: 100%;margin-top:20px;">
      <el-table-column label="序号" type="index" width="60"></el-table-column>
      <el-table-column prop="shipment_name" label="店铺名" width="160"></el-table-column>
      <el-table-column label="商品图片" width="90">
        <template slot-scope="scope">
          <img :src="scope.row.pic_path" alt="" style="width:50px;height:50px;margin:auto;">
        </template>
      </el-table-column>
      <el-table-column prop="title" label="商品名称" width="240"></el-table-column>
      <el-table-column prop="payment" label="订单金额" width="100"></el-table-column>
      <el-table-column prop="tid" label="订单编号" width="170"></el-table-column>
      <el-table-column prop="t_name" label="刷手" width="100"></el-table-column>
      <el-table-column prop="status" label="订单状态" width="100"></el-table-column>
      <el-table-column prop="created" label="创建时间" width="160"></el-table-column>
    </el-table>
    <el-pagination v-if="total >= 20" @current-change="handleCurrentChange" :current-page.sync="page"
                   :page-size="20" layout="total, prev, pager, next" :total="total" style="text-align:right;margin:10px 0;">
    </el-pagination>
  </d2-container>
</template>

<script>
  import { taskorder } from '@api/sys.login';
  export default {
    data(){
      return{
        tableData:[],
        page:1,
        total:0,
        baby:'',
        order_id:'',
        user_name:'',
        shop_name:'',
        timeval:[],
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
      }
    },
    mounted(){
      let params = {
        page:this.page,
        pageSize:20
      }
      this.getUserOrder(params)
    },
    methods:{
      // 获取列表数据
      getUserOrder(params){
        taskorder(params)
          .then((res) => {
            console.log('任务列表',res)
            this.total = res.count
            this.tableData = res.list
          })
      },
      handleCurrentChange(val) {
        this.page = val
        this.onSearch()
      },
      //查询
      onSearch(){
        if(this.timeval.length>0){
          let list = [...this.timeval]
          let index = list[1].indexOf(" ");
          list[1] = list[1].substring(0,list[1].length-index+1) + ' 23:59:59'
          this.timeval[1] = list[1]
        }
        let params = {
          page:this.page,
          pageSize:20,
          begin_time:this.timeval[0],
          end_time:this.timeval[1],
          user_name:this.user_name,
          shop_name:this.shop_name,
          baby:this.baby,
          order_id:this.order_id
        }
        this.getUserOrder(params)
      },
    }
  }
</script>
<style lang="scss" scoped>
  .tasklist{

  }
</style>


